﻿@model ProductIntroduction.Models.Config
           
@{
    ViewBag.Title = "Tạo cấu hình trang web";
}

<script src="../../../../Scripts/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
    function ajaxFileUpload() {
        /*
        prepareing ajax file upload
        url: the url of script file handling the uploaded files
        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
        dataType: it support json, xml
        secureuri:use secure protocol
        success: call back function when the ajax complete
        error: callback function when the ajax failed
            
        */

        $.ajaxFileUpload({
            url: '/Admin/Config/Upload',
            secureuri: false,
            fileElementId: 'fileToUpload',
            dataType: 'json',
            success: function(data, status) {
                alert('abc');
            },
            error: function(data, status, e) {
                alert(e);
            }
        });
        /*
        $.ajaxFileUpload({
            url: '/Admin/Config/Upload',
            secureuri: false,
            fileElementId: 'fileToUpload',
            dataType: 'json',
            data: { name: 'logan', id: 'id' },
            success: function (data, status) {
                $("#divBanner").html('<img src="' + data.FilePath + '" title="Banner" alt="Banner" />');
                $("#urlFile").val(data.FileName);

                alert('abc');
            },
            error: function (data, status, e) {
                if (e) {
                    console.log(e);
                }
            }
        });
        */
    }

    $(document).ready(function () {
        $("#btnUpload").on('click', function () {
            ajaxFileUpload();
        });

        $("#btnSubmit").on('click', function () {
            $("#txtFooter").val(Utils.htmlEncode(CKEDITOR.instances['txtFooterHtml'].getData()));
        });

        //CKEDITOR.replace('txtFooterHtml');

        //starting setting some animation when the ajax starts and completes
        $(document)
            .ajaxStart(function () {
                console.log("Upload start");
            }).ajaxComplete(function () {
                console.log("Upload complete");
            });
    });
</script>

<h2>Tạo cấu hình trang web</h2>

@using (Html.BeginForm("CreateConfig", "Config", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Config</legend>

        <div class="editor-label">Tiêu đề trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteTitle)
            @Html.ValidationMessageFor(model => model.WebsiteTitle)
        </div>

        <div class="editor-label">Tên trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteName)
            @Html.ValidationMessageFor(model => model.WebsiteName)
        </div>

        <div class="editor-label">Slogan trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteSlogan)
            @Html.ValidationMessageFor(model => model.WebsiteSlogan)
        </div>

        <div class="editor-label">@Html.Label("Banner")</div>
        <div class="editor-field">
            <input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">
            <input type="button" id="btnUpload" value="Upload" />
            <span data-valmsg-replace="true" data-valmsg-for="Banner" class="field-validation-valid"></span>
            <input type="hidden" name="Banner" id="urlFile" />
            <div id="divBanner"></div>
        </div>

        <div class="editor-label">@Html.Label("Footer")</div>
        <div class="editor-field">
            <textarea class="ckeditor" id="txtFooterHtml">@Html.DisplayFor(model => model.Footer)</textarea>
            <span class="field-validation-valid" data-valmsg-for="Footer" data-valmsg-replace="true"></span>
            <input type="hidden" name="Footer" id="txtFooter" />
        </div>

        <p>
            <input type="submit" id="btnSubmit" value="Tạo cấu hình" />
        </p>
    </fieldset>
}
<div id="loading">abc</div>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
